home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_5.lha / 6_5 / 6_5srep.h < prev    next >
C/C++ Source or Header  |  1993-08-08  |  664b  |  47 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / define the class to manage the
  6. / actual character string
  7. lass srep
  8.  
  9.    friend class string;
  10.    char *s;
  11.    int size;
  12.    int refcnt;
  13.  
  14.    srep()
  15.    {
  16. refcnt = 1;
  17. s = new char[size = 1];
  18. s[0] = 0;
  19.    }
  20.  
  21.    srep(int sz)
  22.    {
  23. refcnt = 1;
  24. s = new char[size = sz];
  25. s[0] = 0;
  26.    }
  27.  
  28.    srep(char *x)
  29.    {
  30. refcnt = 1;
  31. s = new char[size = strlen(x) + 1];
  32. strcpy(s, x);
  33.    }
  34.  
  35.    srep& operator=(char *x)
  36.    {
  37. delete s;
  38. refcnt = 1;
  39. s = new char[size = strlen(x) + 1];
  40. strcpy(s, x);
  41. return *this;
  42.    }
  43.  
  44.    ~srep()
  45.    { delete s; }
  46. ;
  47.